<template>
	<view class="container"> 
		<uni-swiper-dot v-if="home.adv && home.adv.length > 0" :info="home.adv"  :current="current" field="content" :mode="mode">
			<swiper class="swiper-box" @change="change" indicator-dots="true" indicator-active-color="#ffd900" circular autoplay>
				<swiper-item v-for="(item, index) in home.adv" :key="index">
					<view class="swiper-item">
						<image :src="item.cover" @click="jump(item.jump_type, item.jump_link)" style="width: 750rpx;height: 500rpx;"></image>
					</view>
				</swiper-item>
			</swiper>
		</uni-swiper-dot>
		
		<view class="content" v-if="home.cardList && home.cardList.length > 0">
			<view class="title">
				{{home.cardTitle}}
			</view>
			<view class="more" @click="jump('card_list')">更多</view>
			<view class="list">
				<view class="list_item" v-for="(item,index) in home.cardList" :key="index" @click="jump('card_view', item.id)">
					<image :src="item.cover" mode=""></image>
					<view class="item_text">{{item.title}}</view>
					<view class="item_text1">{{'￥'+item.price}}</view>
				</view>
			</view>
		</view>
		
		<view class="advView" v-if="home.cardAdv.id > 0">
			<image class="img" :src="home.cardAdv.cover"  mode="widthFix" @click="jump(home.cardAdv.jump_type, home.cardAdv.jump_link)"></image>
		</view>
		
		<view class="content" v-if="home.goodsList && home.goodsList.length > 0">
			<view class="title">
				{{home.goodsTitle}}
			</view>
			<view class="more" @click="jump('product_list')">更多</view>
			<view class="list">
				<view class="list_item" v-for="(item,index) in home.goodsList" :key="index" @click="jump('product_view', item.id)">
					<image :src="item.cover" mode=""></image>
					<view class="item_text">{{item.title}}</view>
					<view class="item_text1">{{'￥'+item.price}}</view>
				</view>
			</view>
		</view>
		
		<view class="advView" v-if="home.goodsAdv.id > 0">
			<image class="img" :src="home.goodsAdv.cover"  mode="widthFix" @click="jump(home.goodsAdv.jump_type, home.goodsAdv.jump_link)"></image>
		</view>
		
		<view class="content" v-if="home.article && home.article.length > 0">
			<view class="title">资讯</view>
			<view class="more" @click="jump('article_list')">更多</view>
			<view class="news" v-for="(item, index) in home.article" :key="index"
				@click="jump('article_view', item.id)">
				<view class="left">
					<text>{{item.title}}</text>
					<text>{{item.description}}</text>
					<text style="text-align: right;padding-right: 10rpx;">{{item.create_time}}</text>
				</view>
				<image :src="item.cover" mode="aspectFill"></image>
			</view>
		</view>
		<view class="info"><text @click="jump('agreement', 'about')">关于我们</text> | <text @click="jump('agreement', 'copyright')">版权说明</text></view>
		
	</view>
</template>

<script>
	import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue';
	import serve from '../../static/request.js';
	import common from '../../static/jump.js';
	import ShareIndex from '../../static/share.js';
	import {Base64} from '../../static/base64.min.js';
	export default {
		components: {
			uniSearchBar
		},
		mixins: [ShareIndex],
		data() {
			return {
				home: {},
				current: 0,
				shareItem: {
					title: '',
					path: '',
					imageUrl: '',
				},
			};
		},
		methods: {
			change(e) {
				this.current = e.detail.current;
			},
			getHomeIndex() {
				var self = this;
				serve.request({
					url: '/index/index',
					data: {}
				}).then(res => {
					self.home = res.data;
				});
			},
			getScancode: function() {
				var self = this;
				// 允许从相机和相册扫码
				wx.scanCode({
					// onlyFromCamera: true,
					success: (res) => {
						console.info(res);
					}
				})
			},
			jump(jump_type, jump_link) {
				common.jump(jump_type, jump_link);
			}
		},
		onLoad(option) {
			let scene = option.scene || "";
			if(scene != "") {
				scene = decodeURIComponent(scene);
				let sceneArr = scene.split("=");
				if(sceneArr[0] == 'giveKey') {
					let optionArr = sceneArr[1].split("-");
					uni.setStorageSync('shanhaiKey', optionArr[0]);
					common.jump('giveInfo', optionArr[1]);
					return ;
				}
			}
            this.getHomeIndex();
		},
		async onShow() {
			await this.$defaultLogin();
			this.shareItem.title = '龙鳞黄';
			this.shareItem.path = '/pages/index/index?shanhaiKey='+uni.getStorageSync('shanhaiKey');
			this.shareItem.linePaht = '/pages/index/index';
			this.shareItem.query = 'shanhaiKey='+uni.getStorageSync('shanhaiKey');
			this.getHomeIndex();
		},
		onPullDownRefresh() {
			this.getHomeIndex();
		},

	};
</script>

<style lang="scss" scoped>
	.container {
		color: #39486b;
		background: rgba(204, 204, 204, 0.15);
		
		width: 100%;
		overflow: hidden;
		box-sizing: border-box;

		.swiper-box {
			width: 750upx;
			// margin-top: 250upx;
			height: 500upx;
			background-color: #f0f0f0;
			box-sizing: border-box;

			image {
				width: 750upx;
				height: 422upx;
			}
		}

		.content::before {
			position: absolute;
			right: 33upx;
			top: 45upx;
			content: '';
			border: 1upx solid rgba(57, 72, 107, 0.5);
			border-width: 0 1upx 1upx 0;
			padding: 5upx;
			transform: rotate(-45deg);
			-webkit-transform: rotate(-45deg);
		}

		.content {
			position: relative;
			box-sizing: border-box;
			width: 100%;
			padding: 30upx 0upx 0upx 0upx;
			border-bottom: 16upx rgba(251, 251, 253, 0.8) solid;

			.title {
				width: 360upx;
				height: 24upx;
				margin-left: 30upx;
				position: relative;
				float: left;
				font-size: 24upx;
				text-align: left;
				line-height: 24upx;
				font-weight: bold;
				padding-left: 10px;
			}

			.more {
				width: 130upx;
				height: 24upx;
				margin-right: 10upx;

				position: relative;
				float: right;

				font-size: 24upx;
				text-align: center;

				line-height: 24upx;
				font-weight: bold;

			}

			.title::before {
				content: '';
				position: absolute;
				left: 0;
				top: 0;
				width: 6upx;
				height: 24upx;
				background: rgba(255, 198, 0, 1);
				border-radius: 2upx;
			}
			
			.list {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
				padding-top: 20rpx;
				padding-left: 20rpx;
				width: 96%;
				.list_item {
					width: 330upx;
					padding-bottom: 30upx;
					image {
						width: 330upx;
						height: 330upx;
						border-radius: 2%;
					}
					.item_text{
						margin-top: 25upx;
						font-size:28upx;
						line-height: 50upx;
						color: #333;
						//font-weight:bold;
						text-overflow: -o-ellipsis-lastline;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
					}
					.item_text1{
						margin-top: 20upx;
						font-size:28upx;
						color: #42bfca;
					}
				}
			}

			.news:last-child {
				border-bottom: none;
			}

			.news {
				width: calc(100% - 60upx);
				height: 228upx;
				padding: 30upx 30upx 30upx 0upx;
				margin-left: 45upx;

				display: flex;
				justify-content: space-between;
				box-sizing: border-box;

				border-bottom: 1upx #EBEBEB solid;
				//background-color: #FFEE00;

				.left {
					display: flex;
					flex-direction: column;
					width: 424upx;
					height: 100%;
					justify-content: space-between;
					font-size: 22upx;
					color: #999999;

					text:first-child {
						color: #2C405A;
						font-size: 30upx;
						//font-weight: bold;
						letter-spacing: 2upx;
						line-height: 150%;
						//height: 110upx;
						text-overflow: -o-ellipsis-lastline;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						//font-weight: bold;
					}

					.left_bot {
						.left_item {
							display: flex;
							align-items: center;
							height: 20upx;
							//padding-top: 5upx;
							padding-bottom: 15upx;

							image {
								width: 20upx;
								height: 20upx;
							}

							text {
								margin-left: 8upx;
								font-size: 22upx;
								font-weight: 400;
								color: #999999;
							}
						}

						.left_item:last-child {
							padding-bottom: 16upx;
						}
					}
				}

				image {
					width: 240upx;
					height: 160upx;
					border: 1upx #f0f0f0 solid;
					border-radius: 3%;
				}
			}

			::-webkit-scrollbar {
				display: none;
			}		
		}

		.info {
			margin-bottom: 40upx;
			padding-top: 28upx;
			width: 100%;
			text-align: center;
			font-size: 24upx;
			font-weight: 400;
			color: rgba(57, 72, 107, 0.5);

			text:first-child {
				margin-right: 20upx;
			}

			text:last-child {
				margin-left: 20upx;
			}
		}
	}
	.advView{
		position: relative;  
		//height: 0; 
		//overflow: hidden;
		width: 750upx;
		padding: 0upx 20upx;
		align-items: center;
		justify-content: center;
		.img{
			width: 710upx;
			border: 1upx #EBEBEB solid;
			border-radius: 6upx;
		}
	}
</style>
